
for _,data in ipairs(load_excel('符文装备.xlsx','预设效果')) do
    local name = data.name
    if name then
        ac.lni('item',name,data)
        ac.item(name)
    end
end

local item_class = ac.item.__index

local damage_type = {
    ['力量'] = '|cffff0000%s%%力量伤害|r',
    ['敏捷'] = '|cff00ff00%s%%敏捷伤害|r',
    ['智力'] = '|cff00ffff%s%%智力伤害|r',
    ['全属性'] = '|cffeacb40%s%%全属性伤害|r',
}

function item_class:dmg_ty()
    local str = damage_type[self.sx]
    return str:format(self.rate)
end

function item_class:get_damage()
    local hero = self.owner
    local damage = hero:get(self.sx) * self.rate/100
    return damage
end

function item_class:fw_tip()
    return ('|cff00ff00%s|r'):format(table.concat(self.fw or {},'/'))
end

function item_class:fw_tip()
    return ('|cff00ff00%s|r'):format(table.concat(self.fw or {},'/'))
end

--注册唯一被动
local only_buff = {}
ac.item('唯一被动'){
    on_get = function(self,unit)
        local buff_tag = self.only_buff or self.name
        if only_buff[buff_tag]==nil then
            only_buff[buff_tag] = ac.buff(buff_tag){
                keep = 1,
                cover_type = 1,
                cover_max = 1,
                level = self.lv or 1,
                on_cover = function(buff,new)
                    return new.level>buff.level
                end,
                on_add = function(buff)
                    print(self,unit)
                    self:notify('add_buff',buff,unit)
                end,
            }
        end
        self:gc(unit:add_buff(buff_tag){})
    end,
}

ac.item('攻击触发'){
    temp = '唯一被动',
    abi_tip = [[唯一被动：|n※攻击|cff00ff00'odds'%|r几率对目标范围'dmg_ty'造成伤害|n|n]],
    sx = '全属性',
    rate = 100,
    odds = 100,
    add_buff = function(self,buff,hero)
        buff:gc(hero:event '单位-攻击命中'(function(_,_,target)
            if odd_run(self.odds) and self:is_cooling()==false then
                self:notify('on_run',hero,target)
            end
        end))
    end,
}


--注册唯一被动
local only = {}
ac.item('属性转化'){
    abi_tip = [['abi_name'(唯一被动)：|n每|cff00ff00'data1'%|r'key1'提升|cffff6600'sx_tip'|r|n|n]],
    abi_name = function(self)
        local key1 = ('%s%s'):format(self.key1:sub(1,3),self.key1:sub(7,9))
        local key2 = ('%s%s'):format(self.key2:sub(1,3),self.key2:sub(7,9))
        local name = ('%s转%s'):format(key1,key2)
        return name
    end,
    sx_tip = function(self)
        return sx_tip2(self.key2,self.data2)
    end,
    on_get = function(self,unit)
        local buff_tag = ('%s==>%s'):format(self.key1,self.key2)
        if only[buff_tag]==nil then
            only[buff_tag] = ac.buff(buff_tag){
                temp = '属性转化',
                keep = 1,
                cover_type = 1,
                cover_max = 1,
            }
        end
        self:gc(unit:add_buff(buff_tag){
            key1 = self.key1,
            key2 = self.key2,
            data1 = self.data1,
            data2 = self.data2,
        })
    end,
}

